<?php
// +----------------------------------------------------------------------
// | QSCMS
// +----------------------------------------------------------------------
// | Copyright (c)  2025 https://www.qqss.net All rights reserved.
// +----------------------------------------------------------------------
// | Licensed QSCMS is not free software, commercial use must purchase official license from official website to avoid unnecessary legal disputes.
// +----------------------------------------------------------------------
// | Author: Contract 990504246@qq.com
// +----------------------------------------------------------------------

namespace app\common\model;

use think\Model;

/**
 * 评论点赞模型
 */
class CommentLike extends Model
{
    // 设置表名
    protected $name = 'comment_like';

    // 自动写入时间戳
    protected $autoWriteTimestamp = true;

    /**
     * 关联评论
     */
    public function comment()
    {
        return $this->belongsTo(GoodsComment::class, 'comment_id');
    }

    /**
     * 关联用户
     */
    public function user()
    {
        return $this->belongsTo(User::class, 'user_id');
    }

    /**
     * 判断用户是否已点赞评论
     * 
     * @param int $user_id 用户ID
     * @param int $comment_id 评论ID
     * @return bool 是否已点赞
     */
    public static function isLiked($user_id, $comment_id)
    {
        if (empty($user_id) || empty($comment_id)) {
            return false;
        }

        return self::where([
            'user_id'    => $user_id,
            'comment_id' => $comment_id
        ])->count() > 0;
    }
}